﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Factonomy.AzureUtility.Core
{
    public class ConfigAccount
    {
        XmlNode _node = null;
        //private string _accountName = string.Empty;
        //private string _sharedkey = string.Empty;
        //private bool _local = false;

        public XmlNode Node
        {
            get { return this._node; }
        }

        public string AccountName
        {
            get { return this._node.Attributes["id"].Value; }
            //set { this._accountName = value; }
        }

        public string SharedKey
        {
            get { return this._node["sharedkey"].InnerText; }
            //set { this._sharedkey = value; }
        }

        public bool Enabled
        {
            get {
                if (this._node["enabled"] == null)
                {
                    return true;
                }
                else
                {
                    return this._node["enabled"].InnerText.ToLower() == "true" ? true : false;
                }
            }
            //set { this._sharedkey = value; }
        }

        public bool Local
        {
            get {

                bool result = false;

                if (!bool.TryParse(this._node["local"].InnerText, out result))
                {
                    result = false;
                }

                return result;
            
            }
            //set { this._local = value; }
        }

        public ConfigAccount(string accountName, string sharedKey, bool local, bool enabled)
        {
            //this._accountName = accountName;
            //this._sharedkey = sharedKey;
            //this._local = local;

            Config config = new Config();
            this._node = config.CreateAccountNode(accountName, sharedKey, local, enabled);

        }

        public ConfigAccount(XmlNode node)
        {
            this._node = node;
            //bool result = false;

            //if (!bool.TryParse(node["local"].InnerText, out result))
            //{
            //    result = false;
            //}

            //this._accountName = this._node.Attributes["id"].Value;
            //this._sharedkey = this._node["sharedkey"].InnerText;
            //this._local = result;
        }
    }
}
